//
//  KefuView.swift
//  d11
//
//  Created by rhonin on 2018/10/29.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit
enum KefuViewcliclType {
    case HelpSelf
    case kefuOneClick
    case kefuTwoClick
    case kefuPhoneCall
    case kefuDownClick
}
class KefuView: UIView,UIGestureRecognizerDelegate {

    var kefuclick : ((KefuViewcliclType)->())?
    
    @IBOutlet weak var topView: UIView!
    @IBOutlet weak var topLabel: UILabel!
    @IBOutlet weak var bottomView: UIView!
     @IBOutlet weak var bottomLabel: UILabel!
    @IBOutlet weak var windowView: UIView!
    @IBOutlet weak var downloadViewWdth: NSLayoutConstraint!
    @IBOutlet weak var superVIewWidth: NSLayoutConstraint!
    @IBOutlet weak var leftViewWidth: NSLayoutConstraint!
    @IBOutlet weak var viewTrailing: NSLayoutConstraint!
    @IBAction func tapSuperViewClick(_ sender: UITapGestureRecognizer) {
        self.removeFromSuperview()
    }
    override func awakeFromNib() {
        addBlur()
    }
    @IBAction func tapHelpSelf(_ sender: UITapGestureRecognizer) {
        ToolHelper.statisticsPage(pageName: "底部导航-客服-自助客服")

        if (self.kefuclick != nil) {
            self.kefuclick!(.HelpSelf)
        }
    }
    override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        let point = gestureRecognizer.location(in: self)
        if windowView.frame.contains(point) {
            return false
        }else{
            return true
        }
        
    }
    func addBlur() {
        //首先创建一个模糊效果.light .dark .extraLight
        let blurEffect = UIBlurEffect(style: .dark)
        //接着创建一个承载模糊效果的视图
        let blurView = UIVisualEffectView(effect: blurEffect)
        blurView.alpha=0.8
        //设置模糊视图的大小（全屏）
        blurView.frame = UIApplication.shared.keyWindow!.bounds
        self.insertSubview(blurView, at: 0)
    }
    
    @IBAction func kefuOneClick(_ sender: Any) {
        if (self.kefuclick != nil) {
            self.kefuclick!(.kefuOneClick)
        }
    }
    @IBAction func kefuTwoClick(_ sender: Any) {
         ToolHelper.statisticsPage(pageName: "底部导航-客服-人工客服1")
        if (self.kefuclick != nil) {
            self.kefuclick!(.kefuTwoClick)
        }
    }
    @IBAction func kefu1Call(_ sender: UITapGestureRecognizer) {
          ToolHelper.statisticsPage(pageName: "底部导航-客服-人工客服2")
        if (self.kefuclick != nil) {
            self.kefuclick!(.kefuOneClick)
        }
        
    }
    @IBAction func kefuPhoneCall(_ sender: UITapGestureRecognizer) {
         ToolHelper.statisticsPage(pageName: "底部导航-客服-客户端下载")
        if (self.kefuclick != nil) {
            self.kefuclick!(.kefuTwoClick)
        }
    }
    @IBAction func kefuDownClick(_ sender: UITapGestureRecognizer) {
        if (self.kefuclick != nil) {
            self.kefuclick!(.kefuDownClick)
        }
    }
    func threeButon() {
        leftViewWidth.constant = 0
        viewTrailing.constant =  (superVIewWidth.constant - downloadViewWdth.constant)/2
    }
}
